/**
 * @desc  [自定义校验规则]
 * @example
 *  import { validateRule } from "@/utils/validateRules";
 *  rules: [
 *     { validator: validateRule.emailValue, trigger: 'blur'}
 *  ]
 */

import { isPhoneNumber, isIdNo } from './regRules'

export const validateRules = {
  /**
   * 手机号校验
   */
  phoneNumber(rule, value, callback) {
    if (value && isPhoneNumber(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的手机号码'))
    }
  },
  /**
   * 身份证号校验
   */
  idNo(rule, value, callback) {
    if (value && isIdNo(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的身份证号'))
    }
  }
}
